/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 *  QuartzSRVNexus.m - iPhoneSRV console for Surveyor SRV-1 and SVS 
 *
 *  Created by Nick Kitchener.  Copyright (C) 2009  Surveyor Corporation 
 *            and Nick Kitchener.  All rights reserved.
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details (www.gnu.org/licenses)
 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */

#import "QuartzSRVNexus.h"
#import "SRVConnectOperation.h"

@implementation QuartzSRVNexus

-(id)init {
	if( self = [super init] ) {
		leftQueue = [[SRVNSFrameQueue alloc]init];
		rightQueue = [[SRVNSFrameQueue alloc]init];
	}
	return self;
}

-(void)dealloc {
	[leftQueue release]; leftQueue = nil;
	[rightQueue release]; rightQueue = nil;
	[super dealloc];
}

-(void)setUpBlackfinControllers {
	leftBlackfinController = [[SRVBlackfinController alloc]init];
	rightBlackfinController = [[SRVBlackfinController alloc]init];
}

// queues a frame fetch on each blackfin if enabled
-(void)queueFrameFetch:(NSTimer*)theTimer {
	if() {
		SRVGetJPGFrameOperation *leftOp = [[SRVGetJPGFrameOperation alloc] init];
		[leftOp setCallback:leftQueue];
		[leftOp setOperationTimeout:time];
		[leftBlackfinController queueOperation:leftOp];
	}
	if() {
		SRVGetJPGFrameOperation *rightOp = [[SRVGetJPGFrameOperation alloc] init];
		[rightOp setCallback:rightQueue];
		[rightOp setOperationTimeout:time];
		[rightBlackfinController queueOperation:rightOp];
	}
}

-(void)setupFrameFetchTimer {
	frameTimer = [NSTimer scheduledTimerWithTimeInterval:1
												  target:self
												selector:@selector(queueFrameFetch:)
												userInfo:nil
												 repeats:YES];
}

-(void)cancelFrameFetchTimer {
	[frameTimer invalidate];
}

-(void)operationCompleted:(SRVNSOperation *)operation {
	if([operation class] == [SRVConnectOperation class]) {
		[operation release];
		operation = nil;
	} else {
		
	}
}

-(SRVGetJPGFrameOperation*)leftNextQueuedFrame {
	return [leftQueue pullObject];
}

-(SRVGetJPGFrameOperation*)rightNextQueuedFrame {
	return [rightQueue pullObject];
}



@end
